package com.leyou.page.web;

import com.leyou.page.service.PageService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import javax.annotation.Resource;
import java.util.Map;

/**
 * description: 商品详情接口
 * @author 朱正磊
 * @date 2021-04-11 20:53:33
 */
@Controller
public class PageController {

    @Resource
    private PageService pageService;

    /**
     * description: 跳转到商品详情页
     * @author 朱正磊
     * @date 2021-04-11 20:55:04
     * @param spuId spu的id
     * @param model 模型对象
     * @return 返回商品详情页
     */
    @GetMapping("item/{id}.html")
    public String toItemPage(@PathVariable("id") Long spuId, Model model) {
        // 查询模型数据
        Map<String, Object> attributes = pageService.loadModel(spuId);
        // 封装模型数据
        model.addAllAttributes(attributes);
        // 返回视图地址
        return "item";
    }

}
